package com.example.warehouse.service.serviceImpl;

import com.example.warehouse.entity.Purchase;
import com.example.warehouse.mapper.purchaseMapper;
import com.example.warehouse.page.Page1;
import com.example.warehouse.service.purchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@CacheConfig(cacheNames = "com.example.warehouse.service.serviceImpl.purchaseServiceImpl")
public class purchaseServiceImpl  implements purchaseService {
    @Autowired
    private purchaseMapper purchaseMapper;
    @Override
    public void purchaseAdd(Purchase purchase) {
        purchase.setFactBuyNum(purchase.getBuyNum());
        purchaseMapper.purchaseAdd(purchase);
    }


    @Cacheable(key = "'all:purchase'")
    @Override
    public Page1 PageQuery(Purchase purchase, Page1 page1) {
        int purchaseCount = purchaseMapper.findPurchaseCount(purchase);
        List<Purchase> purchaseList = purchaseMapper.findPagePurchase(page1, purchase);
        page1.setPageNum(purchaseCount);
        page1.setResultList(purchaseList);
        return page1;
    }

    @Override
    public void deleteById(Integer buyId) {
        purchaseMapper.deleteById(buyId);
    }

    @Override
    public void updatePurchase(Purchase purchase) {
        purchaseMapper.updatePurchase(purchase);
    }


}
